package com.utonw.carloan.activity.applyloan;

import android.content.Intent;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.TextView;

import com.utonw.carloan.R;
import com.utonw.carloan.activity.base.BaseActivity;
import com.utonw.carloan.adpter.applyloan.ShowRepayPlanAdapter;
import com.utonw.carloan.bean.applyloan.LoanPlanBean;
import com.utonw.carloan.utils.UIUtils;

import java.util.ArrayList;

/**
 * Created by SEELE on 2017/3/29.
 */

/**
 * 查看还款计划
 */
public class ShowRepayPlanActivity extends BaseActivity {
    //二级列表
    private ExpandableListView mExpandableListView;

    @Override
    public int setLayout() {
        return R.layout.activity_show_repay_plan;
    }

    @Override
    public void initView() {
        mExpandableListView = (ExpandableListView) findViewById(R.id.elv_show_repay_plan);
    }

    @Override
    public void initData() {
        //取消默认方向箭头
        mExpandableListView.setGroupIndicator(null);

        ArrayList<LoanPlanBean.ResultBean.RepayPlanListBean> partGroup = new ArrayList<>();
        ArrayList<LoanPlanBean.ResultBean.RepayPlanListBean.RepayPlanDetailForAppBean> partChild = new ArrayList<>();

        Intent intent = getIntent();
        LoanPlanBean loanData = intent.getParcelableExtra("planList");
        for (int i = 0; i < loanData.getResult().getRepayPlanList().size(); i++) {
            partGroup.add(loanData.getResult().getRepayPlanList().get(i));
        }

        for (int i = 0; i < loanData.getResult().getRepayPlanList().size(); i++) {
            partChild.add(loanData.getResult().getRepayPlanList().get(i).getRepayPlanDetailForApp());
        }


        ShowRepayPlanAdapter adapter = new ShowRepayPlanAdapter(this, partGroup, partChild);

        //注入头布局
        View view = UIUtils.inflate(R.layout.item_expandlist_header_view);
        TextView totalMoney = (TextView) view.findViewById(R.id.tv_total_money);
        totalMoney.setText(loanData.getResult().getRepayTotal());
        mExpandableListView.addHeaderView(view);
        mExpandableListView.setAdapter(adapter);

    }

    @Override
    public String setTitle() {
        return getString(R.string.repay_plan);
    }
}
